/***************************************************************************
                          DataMgr.hpp  -  description
                             -------------------
    begin                : October 29 2009
    copyright            : Copyright 2009, ACKERMANN Thibaut
    email                : tackerma@edu.univ-fcomte.fr
    website              : http://code.google.com/p/nover-project/
    license              : GNU GPL v3
 ***************************************************************************/
/* *************************************************************************
 *  This file is part of NOver-Project.
 *  
 *  NOver-Project is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  NOver-Project is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with NOver-Project.  If not, see <http://www.gnu.org/licenses/>.
 * *************************************************************************/


#ifndef _DATAMGR_
#define _DATAMGR_

#include "Singleton.hpp"

#include <vector>
#include <string>
#include <iostream>
#include <tinyxml.h>

#include "Path.hpp"
#include "Continent.hpp"
#include "Country.hpp"
#include "MyException.hpp"

using std::vector;
using std::string;
using std::cout;
using std::endl;


/**
 * La classe DataMgr s'occupe de charger toutes les données nécessaire au fonctionnement du jeu.
 * (hors images, modeles, etc... qui sont gerés par irrlicht)
 * @author Thibaut Ackermann
 */
class DataMgr : public Singleton<DataMgr>
{
	friend class Singleton<DataMgr>;
public:
	
	/*
	Gere toutes les données.
	
	Donne accès a :
	- liste des continents
	- liste des pays
	- liste des villes
	- données joueurs (r/w)
	*/
	
	void load();
	
	//////////////////////
	// Accesseurs de base
	
	int getContinentsCount()
	{
		return (int)Continents.size();
	}
	
	Continent* getContinentAt(int index)
	{
		return Continents.at(index);
	}
	
	int getCountriesCount()
	{
		return (int)Countries.size();
	}
	
	Country* getCountryAt(int index)
	{
		return Countries.at(index);
	}
	
	///////////////////////////////
	// Accesseurs plus spécifiques
	
	Continent* getContinentByName(string name)
	{
		int taille = static_cast<int>(Continents.size());
		
		for(int i = 0; i<taille; i++)
		{
			if(Continents.at(i)->name.compare(name) == 0)
				return Continents.at(i);
		}
		
		return 0;
	}
	
	Country* getCountryByName(string name)
	{
		int taille = static_cast<int>(Countries.size());
		
		for(int i = 0; i<taille; i++)
		{
			if(Countries.at(i)->name.compare(name) == 0)
				return Countries.at(i);
		}
		
		return 0;
	}
	
	
private:
	DataMgr();
	
	~DataMgr();
	
	void loadContinents() throw (MyException);
	
	Continent* loadContinent(string fichier);
	
	Country* loadCountry(string fichier);
	
	// attributs
	vector<Continent*> Continents;
	vector<Country*> Countries;
};

#endif

